<?php
declare (strict_types = 1);

namespace app\api\controller;
use think\facade\Log;

class Base extends \app\BaseController
{
	public function initialize(){
		parent::initialize();
	}
	
	//输出页面数据
	protected function p_list($data,$extend=[]){
		return $this->getJson(['code'=>0,'data'=>$data,'extend'=>$extend]);
	}
	
	//操作正确
	protected function p_ok($data){
		return $this->getJson(['code'=>200,'data'=>$data]);
	}
	
	//输出页面数据
	protected function p_error($json = [],$ext=null){
		if(is_numeric($json)){
			$code=$json;
			$msg=config_cache_file('codemsg.'.$code);
			$json=[
				'code'=>$code,
				'msg'=>$msg,
			];
		}else if(is_string($json)){
			$json=[
				'code'=>201,
				'msg'=>$json,
			];
		}
		if($ext!=null && !isset($json['data'])){
			$json['data']=$ext;
		}
		return $this->getJson($json);
	}
	
	//记录日志
	public function trace($type='',$info='',$data=''){
		if($data!=''){
			$info.=" | ".$data;
		}
		Log::channel($type)->error($info);
	}
}
